<?php

use \Core\Config\Ref;

// properties
$BasePath = realpath(dirname(__FILE__) . '/../');

// config
return array(
// ----------------------------------------------------------------------------
// Container
// ----------------------------------------------------------------------------		
    '__autoloaders' => array(
        function($className) use ($BasePath) {
            include $BasePath . '/source/' . $className . '.php';
        },
    ),
// ----------------------------------------------------------------------------
    '__postprocessors' => array(
        'settingsPostprocessor',
    ),
// ----------------------------------------------------------------------------
    'settingsPostprocessor' => array(
        'class' => '\Core\Config\PhpSettingsPostprocessor',
        'properties' => array(
            'settings' => array(
                'display_errors' => '1',
                'error_reporting' => E_ALL,
            ),
            'errorHandler' => function($code, $message, $file, $line) {
                if (error_reporting() != 0) {
                    throw new ErrorException($message, 0, $code, $file, $line);
                }
            },
            'exceptionHandler' => function($ex) {
                xdebug_print_function_stack('Uncaught exception: ' . $ex->getMessage());
            },
        ),
    ),
// ----------------------------------------------------------------------------
// Database
// ----------------------------------------------------------------------------
    'db' => array(
        'class' => 'PDO',
        'constructorArgs' => array(
            'mysql:host=localhost;dbname=mydb',
            'user',
            'user'
        ),
    ),
// ----------------------------------------------------------------------------
// MVC framework
// ----------------------------------------------------------------------------		
    'dispatcher' => array(
        'class' => '\Core\MVC\Dispatcher',
        'properties' => array(
            'router' => new Ref('router'),
            'viewHandler' => new Ref('redirectViewHandler'),
        ),
    ),
// ----------------------------------------------------------------------------
    'router' => array(
        'class' => '\Core\MVC\Router',
        'properties' => array(
            'routes' => array(
                // default route
                '' => 'DashboardController/index',
                // user module
                'user' => 'UserController/index',
                'user/add' => 'UserController/add',
                'user/add/edit' => 'UserController/addEdit',
                'user/add/edit:POST' => 'UserController/addEditPost',
                'user/{IdToUserConverter}' => 'UserController/details',
                'user/{IdToUserConverter}/edit' => 'UserController/edit',
                'user/{IdToUserConverter}/edit:POST' => 'UserController/editPost',
                'user/{IdToUserConverter}/remove' => 'UserController/remove',
                'user/{IdToUserConverter}/remove:POST' => 'UserController/removePost',
            ),
        ),
        'containerAware' => true,
        'initMethod' => 'init',
    ),
// ----------------------------------------------------------------------------
    'redirectViewHandler' => array(
        'class' => '\Core\MVC\RedirectViewHandler',
        'properties' => array(
            'adaptedViewHandler' => new Ref('viewHandler'),
            'router' => new Ref('router'),
            'prefix' => 'redirect:',
        ),
    ),
// ----------------------------------------------------------------------------
    'viewHandler' => array(
        'class' => '\Core\MVC\ViewHandler',
        'properties' => array(
            'viewFolder' => ($BasePath . '/views/'),
            'tagFolder' => ($BasePath . '/tags/'),
            'views' => array(
                'StandardLayout' => array(
                    '$view' => 'HelpDesk/default.layout',
                    'text' => new Ref('textSource'),
                    'router' => new Ref('router')
                //'mainMenu' => new Ref('mainMenu')
                ),
                'HelpDesk/Dashboard/index' => array(
                    '$inherit' => 'StandardLayout',
                    'body' => 'HelpDesk/Dashboard/index',
                    'title' => 'helpdesk.dashboard.title'
                ),
                'HelpDesk/Users/index' => array(
                    '$inherit' => 'StandardLayout',
                    'body' => 'HelpDesk/Users/index',
                    'title' => 'helpdesk.users.index.title'
                ),
                'HelpDesk/Users/details' => array(
                    '$inherit' => 'StandardLayout',
                    'body' => 'HelpDesk/Users/details',
                    'title' => 'helpdesk.users.details.title'
                ),
            ),
        ),
        'containerAware' => true,
    ),
// ----------------------------------------------------------------------------
    'textSource' => array(
        'class' => '\Core\MVC\SimpleTextSource',
        'properties' => array(
            'texts' => require ($BasePath . '/config/' . 'text.php')
        ),
    ),
// ----------------------------------------------------------------------------
// HELPDESK - INDEX        
// ----------------------------------------------------------------------------   
    'DashboardController' => array(
        'class' => '\HelpDesk\Dashboard\DashboardController',
    ),
// ----------------------------------------------------------------------------
// HELPDESK - USERS
// ----------------------------------------------------------------------------
    'UserDao' => array(
        'class' => '\HelpDesk\Users\Dao\UserSqlDao',
        'properties' => array(
            'db' => new Ref('db'),
        ),
    ),
// ----------------------------------------------------------------------------
    'IdToUserConverter' => array(
        'class' => '\Core\Converter\IdToObjectConverter',
        'properties' => array(
            'dao' => new Ref('UserDao'),
        ),
    ),
    // ----------------------------------------------------------------------------
    'AddUserSessionStorage' => array(
        'class' => '\Core\Session\SessionStorage',
        'constructorArgs' => array(
            'UserController/add',
        ),
    ),
// ----------------------------------------------------------------------------
    'UserController' => array(
        'class' => '\HelpDesk\Users\Controller\UserController',
        'properties' => array(
            'userDao' => new Ref('UserDao'),
            'addSessionStorage' => new Ref('AddUserSessionStorage'),
        ),
    ),
// ----------------------------------------------------------------------------
// TICTACTOE
// ----------------------------------------------------------------------------		
    'BoardDao' => array(
        'class' => '\TicTacToe\Dao\CookieBoardDao',
        'properties' => array(
            'cookieName' => 'BOARD_COOKIE',
        ),
    ),
// ----------------------------------------------------------------------------		
    'TicTacToeController' => array(
        'class' => '\TicTacToe\Controller\IndexController',
        'properties' => array(
            'boardDao' => new Ref('BoardDao'),
        ),
    ),
);